'''
带工具检索的自定义代理

原因：我们不能在提示词中放置所有工具的描述（由于上下文长度问题），
因此需要动态选择运行时考虑使用的多个工具。


'''

# 导入必要的包
from langchain.agents import Tool, AgentExecutor, LLMSingleActionAgent, AgentOutputParser
from langchain.prompts import StringPromptTemplate
from langchain import OpenAI, SerpAPIWrapper, LLMChain
from typing import List, Union
from langchain.schema import AgentAction, AgentFinish
import re

# 设置工具
# 创建一个合适的工具（搜索）和99个不相关的工具
search = SerpAPIWrapper()
search_tool = Tool(
    name="Search",
    func=search.run,
    description="useful for when you need to answer questions about current events"
)

def fake_func(inp: str) -> str:
    return "foo"

fake_tools = [
    Tool(
        name=f"foo-{i}",
        func=fake_func,
        description=f"a silly function that you can use to get more information about the number {i}"
    )
    for i in range(99)
]
ALL_TOOLS = [search_tool] + fake_tools

